//
//  HomerListViewController.swift
//  SwitfTest
//
//  Created by runone02 on 2018/12/28.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

import UIKit

class HomerListViewController: BaseTableViewController,SecondVCDelegate{

    var titlesId:String!

    override func viewDidLoad() {
        super.viewDidLoad()
        print(titlesId)
        tableView.register(HomeListCell.self, forCellReuseIdentifier: "HomeCell")
//        tableView.rowHeight = 120
        loadMore()
    }

    private func loadMore(){
        //        //下拉刷新
        //        tableView.addPullRefresh({ [weak self] in
        //            DispatchQueue.main.asyncAfter(deadline: afterTime(3)) {
        //                self?.tableView.stopPullRefresh()
        //            }
        //        })
        //
        //        //加载更多
        //        tableView.addFooterRefresh(closure: {[weak self] in
        //            DispatchQueue.main.asyncAfter(deadline: afterTime(3)) {
        //                self?.tableView.stopPullRefresh()
        //            }
        //        })
        
        /////gif下拉刷新
        let arrIdle: NSMutableArray = NSMutableArray.init(capacity: 0)
        for i in 1...60 {
            let name = String.init(format: "dropdown_anim__000%zd", i)
            let image = UIImage.init(named: name)
            arrIdle.add(image!)
        }
        
        let arrRefresh: NSMutableArray = NSMutableArray.init(capacity: 0)
        for i in 1...3 {
            let name = String.init(format: "dropdown_loading_0%zd", i)
            let image = UIImage.init(named: name)
            arrRefresh.add(image!)
        }
        
        tableView.addGifPullRefresh(idleImages: arrIdle, refreshImages: arrRefresh, closure: { [weak self] in
            DispatchQueue.main.asyncAfter(deadline: afterTime(6)) {
                self?.tableView.stopPullRefresh()
            }
        })
        
        tableView.addFooterRefresh(closure: {[weak self] in
            DispatchQueue.main.asyncAfter(deadline: afterTime(3)) {
                self?.tableView.stopPullRefresh()
            }
        })
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source
    override func numberOfSections(in tableView: UITableView) -> Int {

        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
            return 120
 }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier:"HomeCell", for: indexPath) as! HomeListCell

        //点击回调
        cell.sendValueBlock = {(index:Int,str:String)in

            }
        cell.heightBlock = {(height:CGFloat)in
            
        }
        return cell
    }
    

    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        let tevc = testViewController()
        tevc.delegate = self
 
        self.navigationController?.pushViewController(tevc, animated: true)
    }
    
    
    /// 实现代理方法
    func changeColor(tempString: NSString) {
//        print("代理返回 : " + (tempString as String))
    }
 
}
